package com.gl.doc.operation.impl;

import com.gl.doc.builder.WordDocument;
import com.gl.doc.model.Paragraph;
import com.gl.doc.operation.WordContentRead;
import com.gl.doc.support.ParagraphLookupSupport;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * word文档内容读取默认实现
 */
@Slf4j
public class DefaultWordContentRead implements WordContentRead {

    @Override
    public List<Paragraph> getParagraphs(WordDocument wordDocument) {
        List<Paragraph> paragraphs = new ArrayList<>();
        ParagraphLookupSupport.paragraphLookup(wordDocument, paragraphs::add);
        return paragraphs;
    }

    @Override
    public Paragraph getParagraph(WordDocument wordDocument, Integer index) {
        List<Paragraph> paragraphs = this.getParagraphs(wordDocument);
        return paragraphs.get(index);
    }
}
